test(command-integrator): write _make_package fixtures as utf-8 bytes for Windows#1123
Closed
danielmeppiel wants to merge 1 commit intomainfrom
Closed
test(command-integrator): write _make_package fixtures as utf-8 bytes for Windows#1123danielmeppiel wants to merge 1 commit intomainfrom
danielmeppiel wants to merge 1 commit intomainfrom
Conversation
… for Windows
The _make_package helper used by TestCursorCommandPanelFindings calls
Path.write_text(content), which on Windows defaults to the cp1252
encoder and raises UnicodeEncodeError on the U+E041 tag character that
test_critical_security_finding_blocks_write deliberately injects to
exercise the post-transform critical-finding gate.
Switch to write_bytes(content.encode('utf-8')), matching the canonical
pattern already used in this repo for fixture content that must round-
trip exactly (sha256 integrity helpers in tests/unit/install/ and
tests/unit/bundle/). This also avoids write_text's Windows newline
translation, so the bytes on disk match the literal test input.
Failing run: https://github.com/microsoft/apm/actions/runs/25286532040
job 74131700555 (Build & Test, windows-latest).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a Windows-only unit test failure in the command integrator test suite by writing prompt fixture files as raw UTF-8 bytes instead of using the platform-default text encoding.
Changes:
- Update the shared
_make_packagetest helper to write fixture content viaPath.write_bytes(content.encode("utf-8"))to avoid Windowscp1252encoding errors and newline translation.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/integration/test_command_integrator.py | Switch fixture file writes to UTF-8 bytes to make the security-finding test deterministic on Windows. |
Copilot's findings
- Files reviewed: 1/1 changed files
- Comments generated: 0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR
Fix Windows-only test failure introduced when
_make_package(shared helper attests/unit/integration/test_command_integrator.py:25) writes fixture content viaPath.write_text(content). On Windows the default codec iscp1252, which raisesUnicodeEncodeErrorfor theU+E041tag character thattest_critical_security_finding_blocks_writedeliberately injects. Switch towrite_bytes(content.encode("utf-8")).Failing run
https://github.com/microsoft/apm/actions/runs/25286532040/job/74131700555 (Build & Test, windows-latest, x86_64).
7366 passed, 1 failed.
Why this is the right fix
The test purposefully injects
U+E041to exercise the post-transform critical-finding gate (the production code is supposed to block this character on the way in, not encode it for storage). The fixture only needs to write the literal bytes to disk for the gate to read back -- so we should NOT round-trip via the platform default text codec.This matches the canonical fixture pattern already used in this repo whenever bytes-on-disk must equal bytes-in-test (e.g. sha256 integrity helpers in
tests/unit/install/test_install_local_bundle.py:68,tests/integration/test_install_local_bundle_e2e.py:64, andtests/unit/bundle/test_local_bundle.py:82-- the last one fixed in PR #1103). It also sidestepswrite_text's Windows\n->\r\ntranslation, which the failing trace shows happening in the input string.Validation
uv run --extra dev pytest tests/unit/integration/test_command_integrator.py::TestCursorCommandPanelFindings -x-- 8 passed.ruff checkandruff format --checkon the touched file -- silent.write_textcalls in the same file are pure ASCII and remain unchanged.Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com